<template>
  <div>
    <div :style="childrenStyle" @mouseleave="mouseleave"  class="animate__animated  animate__fadeInLeft childrenNav">
      <div class="shop">
        <template v-if="childrenData.length>0">
          <div class="label"><h2>{{goodsType}}</h2></div>
          <div style="margin-top:30px" class="info">
            <span class="shopImg">
              <img :src="getImgUrl(currentInfo)" alt="" width="250px" height="300px">
              <!-- <img src="~@/assets/img/list/shop1.webp" alt="" width="250px" height="300px"> -->
            </span>
            <span class="shopImg list_right">
              <p>商品：{{currentInfo.goods_name}}</p>
              <p>规格：{{currentInfo.goods_name}}</p>
              <p>描述：{{currentInfo.goods_describe}}</p>
              <p>价格：{{currentInfo.goods_price}}.00</p>
              <span class="more" @click="linkDetails">查看详情</span>
            </span>
          </div>
        </template>
        <template v-else>
          <div>该类型暂无商品</div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import { getRandomGoods } from "@/js/api/home";
export default {
  name:'childrenNav',
  props:{
    childrenStyle: {
      type: Object,
      default: function(){
        return {}
      }
    },
  },
  data(){
    return {
      currentInfo:{},
      childrenData:[],
      goodsType:"",
    }
  },
  created(){
  },
  methods:{
    show(val){
      this.goodsType = val.label
      getRandomGoods({type:val.value}).then(response=>{
        if(response.data.state){
          if(response.data.data == null){
            this.childrenData = []
            this.currentInfo = {}
          }else{
            this.childrenData = [response.data.data]
            this.currentInfo = this.childrenData[0]
          }
        }
      })
    },
    getImgUrl(url){
      if(url.goods_src){
        return require("@/assets/img/"+url.goods_src);
      }
    },
    mouseleave(){
      this.currentInfo = {}
      this.$emit("leave")
    },
    linkDetails(){
      let obj = this.currentInfo
      obj.typeStr = this.goodsType
      this.$emit("linkDetails",obj)
    },
  }
}
</script>

<style lang="less">
  .childrenNav{
    box-shadow: -60px 0px 100px -90px #000000,60px 0px 100px -90px #000000;
    background-color: white;
    border-radius:0 3px 3px 0;
    border: 1px solid #e0e0e0;
    position: absolute;
    .shop{
      padding: 20px 30px;
      h2{
        margin: 0 0;
      }
      .label{
        text-align: center;
        color: #ff6700;
        font-size: 18px;
      }
      .info{
        display: flex;
        justify-content:space-around
      }
      .list_right{
        text-overflow:ellipsis;
        font-size: 20px;
        p:not(:first-child){
          margin: 0;
          margin-top: 10px;
        }
      }
      .more{
        margin-top: 30px;
        cursor: pointer;
        display: inline-block;
        text-align: center;
        width: 100%;
        color: #ff6700;
      }
    }
  }
</style>